package CryptUtil

import "NetFrameWork/util/random"

type CRand32 struct {
	seed1 int64
	seed2 int64
	seed3 int64
}

func (r CRand32) Seed(seed1 int32, seed2 int32, seed3 int32) {
	r.seed1 = int64(seed1 | 0x100000)
	r.seed2 = int64(seed2 | 0x1000)
	r.seed3 = int64(seed3 | 0x10)
}

func (r CRand32) Random() int64 {
	r.seed1 = r.seed1<<12 ^ r.seed1>>19 ^ (r.seed1>>6^r.seed1<<12)&0x1FFF
	r.seed2 = 16*r.seed2 ^ r.seed2>>25 ^ (16*r.seed2^r.seed2>>23)&0x7F
	r.seed3 = r.seed3>>11 ^ r.seed3<<17 ^ (r.seed3>>8^r.seed3<<17)&0x1FFFFF
	return (r.seed1 ^ r.seed2 ^ r.seed3) & 0xFFFFFFFF
}

func NewCRand32() CRand32 {
	r := CRand32{}
	r.Seed(Randomizer.NextInt_(), Randomizer.NextInt_(), Randomizer.NextInt_())
	return r
}
